﻿using Furion.DynamicApiController;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace IndoorPosition.Server.Application
{
    /// <summary>
    /// 配置参数相关服务接口
    /// </summary>
    public class ConfigurationAppService : IDynamicApiController
    {
        IConfigurationService _configurationService;

        public ConfigurationAppService(IConfigurationService configurationService)
        {
            _configurationService = configurationService;
        }

        /// <summary>
        /// 添加参数
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        /// <exception cref="Exception"></exception>
        public async Task Add(ConfigurationInputDto input)
        {
            await _configurationService.AddAsync(input);
        }

        /// <summary>
        /// 添加或更新参数
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task AddOrUpdateAsync(ConfigurationInputDto input)
        { 
            await _configurationService.AddOrUpdateAsync(input);
        }

        /// <summary>
        /// 获取参数
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public async Task<ConfigurationDto> Get(string key)
        {
            return await _configurationService.GetAsync(key);
        }

        /// <summary>
        /// 获取所有参数列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<List<ConfigurationDto>> ListAsync()
        {
            return await _configurationService.ListAsync();
        }

        /// <summary>
        /// 更新参数
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task UpdateAsync(ConfigurationDto input)
        {
            await _configurationService.UpdateAsync(input);
        }

        /// <summary>
        /// 删除参数
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task DeleteAsync(int id)
        {
            await _configurationService.DeleteAsync(id);
        }
    }
}
